enable_testing()
find_package(GTest MODULE REQUIRED)

# LASlib
find_package(LASlib)

set(PostgreSQL_TYPE_INCLUDE_DIR /usr/include/postgresql/)
find_package(libpqxx)

#find_package (SQLite3)
#if (SQLITE3_FOUND)
#    include_directories(${SQLITE3_INCLUDE_DIRS})
#    target_link_libraries (tutorial ${SQLITE3_LIBRARIES})
#endif (SQLITE3_FOUND)

include_directories(include)

add_library(reader reader/data_reader.cpp reader/kitti_reader.cpp reader/or_reader.cpp reader/ns_reader.cpp reader/nsh_reader.cpp
        reader/semantic_kitti_reader.cpp)
target_link_libraries(reader common)

if(LASlib_FOUND)
add_executable(las_load_test las_test.cpp)
target_link_libraries(las_load_test LASlib reader ${GTEST_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME las_load_test COMMAND las_load_test)

add_executable(las_load_map las/load_map.cpp)
target_link_libraries(las_load_map LASlib reader ${GTEST_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME las_load_map COMMAND las_load_map)
endif(LASlib_FOUND)

add_executable(pcd_load_test pcd_test.cpp)
target_link_libraries(pcd_load_test benxdb reader ${GTEST_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} sqlite3)
add_test(NAME pcd_load_test COMMAND pcd_load_test)

add_executable(benxdb_load_test benxdb_test.cpp)
target_link_libraries(benxdb_load_test benxdb reader ${GTEST_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME benxdb_load_test COMMAND benxdb_load_test)

add_executable(benxdb_load_map_test picsad/load_map.cpp)
target_link_libraries(benxdb_load_map_test benxdb reader ${GTEST_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME benxdb_load_map_test COMMAND benxdb_load_map_test)

add_executable(benxdb_query_test picsad/query_test.cpp)
target_link_libraries(benxdb_query_test benxdb reader ${GTEST_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
add_test(NAME benxdb_query_test COMMAND benxdb_query_test)

# if(libpqxx_FOUND)
# add_executable(post_flat_test post_flat_test.cpp)
# target_link_libraries(post_flat_test reader ${GTEST_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} -lpqxx -lpq)
# add_test(NAME post_flat_test COMMAND post_flat_test)

# add_executable(pg_block_test pg_block_test.cpp)
# target_link_libraries(pg_block_test reader ${GTEST_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} -lpqxx -lpq)
# add_test(NAME pg_block_test COMMAND pg_block_test)
# endif(libpqxx_FOUND)

file(COPY config.ini DESTINATION .)
file(COPY config.toml DESTINATION .)
